<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
    <title>系统登录</title>
</head>
<link rel="stylesheet" href="/static/style.css"/>
<script src="/static/jquery.min.js"></script>
<body>
<form class="m-form m-form-ht n-login" id="inputForm" action="${pageContext.request.contextPath}/login" onsubmit="return false;" autocomplete="off">
    <div style="width: 490%;text-align: center;font-size: 18px;">新闻后台登录
    </div>
    <div class="fmitem">
        <label class="fmlab">账号：</label>
        <div class="fmipt">
            <input class="u-ipt" id="account" name="account" value="" autofocus/>
        </div>
    </div>
    <div class="fmitem">
        <label class="fmlab">密码：</label>
        <div class="fmipt">
            <input class="u-ipt" id="password" type="password" value="" name="password"/>
        </div>
    </div>
    <div class="fmitem fmitem-nolab fmitem-btn">
        <div class="fmipt" style="display: inline-block;width: 100%">
            <button onclick="login()" style="width: 40%;float: left;margin-right: 10px"
                    class="u-btn u-btn-primary u-btn-lg u-btn-block">登 录
            </button>
            <button type="button" onclick="register()" style="width: 40%" class="u-btn u-btn-primary u-btn-lg u-btn-block">注 册</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    //登录
    function login(){
        var account = $("#account").val();
        var password = $("#password").val();
        if (account == "") {
            alert("账号不能为空");
            return false;
        }
        if (password == "") {
            alert("密码不能为空");
            return false;
        }
        var params = serializeFormToObject($("#inputForm"));
        var url = $("#inputForm").attr("action");//请求URL
        $.post(url,params,function (data){
            if (data.code==200){
                window.location.href="index.jsp"
            }else {
                alert(data.msg);
            }
        });
    }
    //注册
    function register(){
        window.location.href="register.jsp"
    }
    //将表单对象序列化成object对象
    function serializeFormToObject(form){
        var o={};
        $.each(form.serializeArray(),function(index){
            if(o[this['name']]){
                o[this['name']] = o[this['name']]+","+this['value'];
            }else{
                o[this['name']] = this['value'];
            }
        });
        return o;
    }
</script>
</html>
